package com.acme.Applications;

import java.io.*;
import java.net.Socket;

public class IOExperiment {
    //seems like it's time to reorganize packages.
    //could be shame if haven't been because of ready src's for labs

    public static void main(String... args) {
        System.out.println(new File("").getAbsolutePath());
        //weren't doing more practice, just staring onto the board:
        //InputStream is = new FileInputStream("file");
        //InputStreamReader isr = new InputStreamReader(is, "encoding");
        //BufferedReader br = new BufferedReader(isr, bufferSize);

        try (
            Socket socket = new Socket("127.0.0.1", 666);
            DataOutputStream out = new DataOutputStream(socket.getOutputStream());
            DataInputStream in = new DataInputStream(socket.getInputStream())
        ) {
            String response;
            while (true) {
                out.writeUTF(new BufferedReader(new InputStreamReader(System.in)).readLine());
                response = in.readUTF();
                System.out.println(response);
                if ("end".equals(response)) {
                    break;
                }
            }
        } catch (Exception e) {
            System.err.println(e);
        }
    }
}
